# knowledge.py
from database.database import db


class Knowledge(db.Model):
    __tablename__ = 'knowledge'

    id = db.Column(db.Integer, primary_key=True)
    kno_id = db.Column(db.String(255), nullable=False)
    kno_title = db.Column(db.String(255), nullable=False)
    kno_type = db.Column(db.String(255), nullable=False)
    kno_url = db.Column(db.Text, nullable=False)
    kno_authid = db.Column(db.String(255), nullable=False)
    kno_style = db.Column(db.Integer, nullable=False)
    kno_createtime = db.Column(db.DateTime, nullable=False)
    kno_updatetime = db.Column(db.DateTime, nullable=False)

    def __init__(self, kno_id, kno_title, kno_type, kno_url, kno_authid, kno_style, kno_createtime, kno_updatetime):
        self.kno_id = kno_id
        self.kno_title = kno_title
        self.kno_type = kno_type
        self.kno_url = kno_url
        self.kno_authid = kno_authid
        self.kno_style = kno_style
        self.kno_createtime = kno_createtime
        self.kno_updatetime = kno_updatetime

    def to_dict(self):
        return {
            'id': self.id,
            'kno_id': self.kno_id,
            'kno_title': self.kno_title,
            'kno_type': self.kno_type,
            'kno_url': self.kno_url,
            'kno_authid': self.kno_authid,
            'kno_style': self.kno_style,
            'kno_createtime': self.kno_createtime.isoformat() if self.kno_createtime else None,
            'kno_updatetime': self.kno_updatetime.isoformat() if self.kno_updatetime else None
        }